import { View } from "@tarojs/components";
import { useRouter } from "@tarojs/taro";
//import "./index.scss";

import { styled } from "@linaria/react";
import { useCallContainerGet } from "@/tools/useCallContainer";

import Taro from "@tarojs/taro";  
import SearchBar from "@/components/SearchBar";

import DishItem from "../restaurant/components/DishItem";

export default function searchDishes() {
  const { params } = useRouter();
  console.log(`/dishes/search?page=1&per_page=10&search_str=${encodeURIComponent(String(params.sst))}`);
  const [{ dataList, total_Pages }] = useCallContainerGet(
    params.sst && `/dishes/search?page=1&per_page=10&search_str=${encodeURIComponent(String(params.sst))}`
  );
  // useEffect(() => {
  //   const response = await wx.cloud.callContainer({
  //     config: {
  //       env: 'prod-0g6virbea3062996',
  //     },
  //     path: `/dishes/search?page=1&per_page=10&search_str=${encodeURIComponent(String(params.sst))}`,
  //     method: 'GET',
  //     header:{
  //       'X-WX-SERVICE':'flask-92sh',
  //     },

  //   })
  // }, []);
  const searchRestaurants = (sst:string) => {
    Taro.navigateTo({url:"../searchRestaurants/index?sst="+sst});
  }

  const searchDishes = (sst:string) => {
    if (params.sst != sst)
        Taro.navigateTo({url:"../searchDishes/index?sst="+sst});
  }
  console.log("dataList"+dataList);
  return (
    <View style={{ padding: "10px" ,flexDirection:"column"}}>
        <SearchBar onClick1={searchRestaurants} onClick2={searchDishes} defaultText={params.sst} defaultOption={1}/>
        
        <DishItemList>
              {(dataList??[]).map((dish1) => (
                <View style={{marginTop:"12px", paddingLeft:"10px", border:"2px solid #dadada", borderRadius:"10px", boxShadow:"0 0 4px rgba(0,0,0,.35)"}}>
                  <DishItem dish={dish1} />
                </View>
              ))} 
        </DishItemList>
        
          
    </View>
  );
}

const DishItemList = styled(View)`
  padding: 0 20px;
  display: flex;
  flex-direction: column;
`;